/**
 * 示例数据
 * 用于测试应用功能
 */

// 生成示例日程数据
export const generateSampleSchedules = () => {
	const now = new Date()
	const schedules = []
	
	// 今天的日程
	schedules.push({
		id: 'sample_1',
		title: '团队周会',
		description: '讨论本周工作进展和下周计划',
		startTime: new Date(now.getFullYear(), now.getMonth(), now.getDate(), 9, 0).toISOString(),
		endTime: new Date(now.getFullYear(), now.getMonth(), now.getDate(), 10, 0).toISOString(),
		priority: 'high',
		tags: ['工作', '会议'],
		completed: false,
		reminder: {
			enabled: true,
			beforeMinutes: 15
		},
		repeat: 'weekly',
		createdAt: new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString()
	})
	
	schedules.push({
		id: 'sample_2',
		title: '完成项目报告',
		description: '整理本月项目进展，准备月度汇报材料',
		startTime: new Date(now.getFullYear(), now.getMonth(), now.getDate(), 14, 0).toISOString(),
		endTime: new Date(now.getFullYear(), now.getMonth(), now.getDate(), 17, 0).toISOString(),
		priority: 'urgent',
		tags: ['工作', '文档'],
		completed: false,
		reminder: {
			enabled: true,
			beforeMinutes: 30
		},
		repeat: 'none',
		createdAt: new Date(now.getTime() - 2 * 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(now.getTime() - 2 * 24 * 60 * 60 * 1000).toISOString()
	})
	
	// 明天的日程
	const tomorrow = new Date(now.getTime() + 24 * 60 * 60 * 1000)
	schedules.push({
		id: 'sample_3',
		title: '健身房训练',
		description: '胸部和三头肌训练',
		startTime: new Date(tomorrow.getFullYear(), tomorrow.getMonth(), tomorrow.getDate(), 19, 0).toISOString(),
		endTime: new Date(tomorrow.getFullYear(), tomorrow.getMonth(), tomorrow.getDate(), 20, 30).toISOString(),
		priority: 'medium',
		tags: ['健康', '运动'],
		completed: false,
		reminder: {
			enabled: true,
			beforeMinutes: 60
		},
		repeat: 'daily',
		createdAt: new Date(now.getTime() - 3 * 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(now.getTime() - 3 * 24 * 60 * 60 * 1000).toISOString()
	})
	
	schedules.push({
		id: 'sample_4',
		title: '购买生活用品',
		description: '牙膏、洗发水、纸巾等日常用品',
		startTime: new Date(tomorrow.getFullYear(), tomorrow.getMonth(), tomorrow.getDate(), 10, 0).toISOString(),
		endTime: new Date(tomorrow.getFullYear(), tomorrow.getMonth(), tomorrow.getDate(), 11, 0).toISOString(),
		priority: 'low',
		tags: ['生活', '购物'],
		completed: false,
		reminder: {
			enabled: false,
			beforeMinutes: 15
		},
		repeat: 'none',
		createdAt: new Date(now.getTime() - 1 * 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(now.getTime() - 1 * 24 * 60 * 60 * 1000).toISOString()
	})
	
	// 后天的日程
	const dayAfterTomorrow = new Date(now.getTime() + 2 * 24 * 60 * 60 * 1000)
	schedules.push({
		id: 'sample_5',
		title: '学习 Vue.js 新特性',
		description: '了解 Vue 3 的 Composition API 和新功能',
		startTime: new Date(dayAfterTomorrow.getFullYear(), dayAfterTomorrow.getMonth(), dayAfterTomorrow.getDate(), 20, 0).toISOString(),
		endTime: new Date(dayAfterTomorrow.getFullYear(), dayAfterTomorrow.getMonth(), dayAfterTomorrow.getDate(), 22, 0).toISOString(),
		priority: 'medium',
		tags: ['学习', '技术'],
		completed: false,
		reminder: {
			enabled: true,
			beforeMinutes: 15
		},
		repeat: 'none',
		createdAt: new Date(now.getTime() - 4 * 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(now.getTime() - 4 * 24 * 60 * 60 * 1000).toISOString()
	})
	
	// 已完成的日程
	const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000)
	schedules.push({
		id: 'sample_6',
		title: '阅读技术文章',
		description: '阅读关于前端性能优化的文章',
		startTime: new Date(yesterday.getFullYear(), yesterday.getMonth(), yesterday.getDate(), 21, 0).toISOString(),
		endTime: new Date(yesterday.getFullYear(), yesterday.getMonth(), yesterday.getDate(), 22, 0).toISOString(),
		priority: 'low',
		tags: ['学习', '阅读'],
		completed: true,
		reminder: {
			enabled: true,
			beforeMinutes: 15
		},
		repeat: 'none',
		createdAt: new Date(now.getTime() - 5 * 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(yesterday.getTime() + 60 * 60 * 1000).toISOString()
	})
	
	schedules.push({
		id: 'sample_7',
		title: '整理房间',
		description: '清理桌面，整理书籍和文件',
		startTime: new Date(yesterday.getFullYear(), yesterday.getMonth(), yesterday.getDate(), 15, 0).toISOString(),
		endTime: new Date(yesterday.getFullYear(), yesterday.getMonth(), yesterday.getDate(), 16, 0).toISOString(),
		priority: 'medium',
		tags: ['生活', '清洁'],
		completed: true,
		reminder: {
			enabled: false,
			beforeMinutes: 15
		},
		repeat: 'weekly',
		createdAt: new Date(now.getTime() - 6 * 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(yesterday.getTime() + 2 * 60 * 60 * 1000).toISOString()
	})
	
	// 一周后的日程
	const nextWeek = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000)
	schedules.push({
		id: 'sample_8',
		title: '医院体检',
		description: '年度健康体检，包括血常规、心电图等',
		startTime: new Date(nextWeek.getFullYear(), nextWeek.getMonth(), nextWeek.getDate(), 8, 0).toISOString(),
		endTime: new Date(nextWeek.getFullYear(), nextWeek.getMonth(), nextWeek.getDate(), 11, 0).toISOString(),
		priority: 'high',
		tags: ['健康', '医疗'],
		completed: false,
		reminder: {
			enabled: true,
			beforeMinutes: 1440 // 1天前
		},
		repeat: 'yearly',
		createdAt: new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000).toISOString()
	})
	
	// 过期的日程
	const lastWeek = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000)
	schedules.push({
		id: 'sample_9',
		title: '提交月度总结',
		description: '向主管提交本月工作总结报告',
		startTime: new Date(lastWeek.getFullYear(), lastWeek.getMonth(), lastWeek.getDate(), 17, 0).toISOString(),
		endTime: new Date(lastWeek.getFullYear(), lastWeek.getMonth(), lastWeek.getDate(), 18, 0).toISOString(),
		priority: 'urgent',
		tags: ['工作', '报告'],
		completed: false,
		reminder: {
			enabled: true,
			beforeMinutes: 60
		},
		repeat: 'monthly',
		createdAt: new Date(now.getTime() - 10 * 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(now.getTime() - 10 * 24 * 60 * 60 * 1000).toISOString()
	})
	
	schedules.push({
		id: 'sample_10',
		title: '朋友聚餐',
		description: '和大学同学聚餐，聊聊近况',
		startTime: new Date(lastWeek.getFullYear(), lastWeek.getMonth(), lastWeek.getDate(), 18, 30).toISOString(),
		endTime: new Date(lastWeek.getFullYear(), lastWeek.getMonth(), lastWeek.getDate(), 21, 0).toISOString(),
		priority: 'medium',
		tags: ['生活', '社交'],
		completed: true,
		reminder: {
			enabled: true,
			beforeMinutes: 30
		},
		repeat: 'none',
		createdAt: new Date(now.getTime() - 8 * 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(lastWeek.getTime() + 3 * 60 * 60 * 1000).toISOString()
	})
	
	// 添加一些任务类型的示例数据
	schedules.push({
		id: 'task_1',
		type: 'task',
		title: '阅读《深度工作》',
		description: '提升专注力和工作效率',
		startTime: now.toISOString(),
		endTime: new Date(now.getTime() + 365 * 24 * 60 * 60 * 1000).toISOString(), // 一年后
		priority: 'medium',
		tags: ['学习', '自我提升'],
		completed: false,
		reminder: {
			enabled: false,
			beforeMinutes: 15
		},
		repeat: 'none',
		createdAt: new Date(now.getTime() - 2 * 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(now.getTime() - 2 * 24 * 60 * 60 * 1000).toISOString()
	})
	
	schedules.push({
		id: 'task_2',
		type: 'task',
		title: '整理电脑文件',
		description: '清理桌面，整理文档分类',
		startTime: now.toISOString(),
		endTime: new Date(now.getTime() + 365 * 24 * 60 * 60 * 1000).toISOString(),
		priority: 'low',
		tags: ['生活', '整理'],
		completed: false,
		reminder: {
			enabled: false,
			beforeMinutes: 15
		},
		repeat: 'none',
		createdAt: new Date(now.getTime() - 1 * 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(now.getTime() - 1 * 24 * 60 * 60 * 1000).toISOString()
	})
	
	schedules.push({
		id: 'task_3',
		type: 'task',
		title: '学习Vue3新特性',
		description: '掌握Composition API和新的响应式系统',
		startTime: now.toISOString(),
		endTime: new Date(now.getTime() + 365 * 24 * 60 * 60 * 1000).toISOString(),
		priority: 'high',
		tags: ['工作', '学习', '技术'],
		completed: true,
		reminder: {
			enabled: false,
			beforeMinutes: 15
		},
		repeat: 'none',
		createdAt: new Date(now.getTime() - 5 * 24 * 60 * 60 * 1000).toISOString(),
		updatedAt: new Date(now.getTime() - 1 * 24 * 60 * 60 * 1000).toISOString()
	})
	
	return schedules
}

// 初始化示例数据
export const initSampleData = () => {
	try {
		// 检查是否已有数据
		const existingSchedules = uni.getStorageSync('schedules')
		const existingSettings = uni.getStorageSync('settings')
		
		// 如果没有日程数据，创建示例数据
		if (!existingSchedules) {
			const sampleSchedules = generateSampleSchedules()
			uni.setStorageSync('schedules', JSON.stringify(sampleSchedules))
			console.log('已创建示例日程数据')
		}
		
		// 如果没有设置数据，创建默认设置
		if (!existingSettings) {
			const defaultSettings = {
				notifications: {
					enabled: true,
					sound: true,
					vibrate: true,
					beforeMinutes: [5, 15, 30, 60, 1440]
				},
				display: {
					theme: 'light',
					fontSize: 'medium',
					showCompleted: true
				},
				defaults: {
					priority: 'medium',
					tags: ['工作', '生活', '学习', '健康', '娱乐']
				},
				data: {
					autoBackup: true,
					backupFrequency: 'daily',
					lastBackupTime: null
				}
			}
			uni.setStorageSync('settings', JSON.stringify(defaultSettings))
			console.log('已创建默认设置数据')
		}
		
		return true
	} catch (error) {
		console.error('初始化示例数据失败:', error)
		return false
	}
}

// 清除所有数据
export const clearAllData = () => {
	try {
		uni.removeStorageSync('schedules')
		uni.removeStorageSync('settings')
		uni.removeStorageSync('backup_data')
		console.log('已清除所有数据')
		return true
	} catch (error) {
		console.error('清除数据失败:', error)
		return false
	}
} 